package sample.model;

import javafx.beans.property.SimpleStringProperty;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class ServerConfigurationModel {
    private SimpleStringProperty serverName = new SimpleStringProperty();//服务器名称
    private SimpleStringProperty hostIP = new SimpleStringProperty();//IP地址
    private SimpleStringProperty CPU = new SimpleStringProperty();//cpu 物理 核数 逻辑
    private SimpleStringProperty MEM = new SimpleStringProperty();//内存
    private SimpleStringProperty diskSpace = new SimpleStringProperty();//磁盘空间
    private SimpleStringProperty javaVersion = new SimpleStringProperty();//java 版本
    private SimpleStringProperty hostName = new SimpleStringProperty();//主机名
    private SimpleStringProperty systemType = new SimpleStringProperty();//系统类型
    private SimpleStringProperty systemVersion = new SimpleStringProperty();//系统版本
    private SimpleStringProperty serverDate = new SimpleStringProperty();//系统当前时间

    public ServerConfigurationModel(String serverName, String hostIP, String CPU, String MEM, String diskSpace, String javaVersion, String hostName, String systemType, String systemVersion, String serverDate){
        this.serverName.set(serverName);
        this.hostIP.set(hostIP);
        this.CPU.set(CPU);
        this.MEM.set(MEM);
        this.diskSpace.set(diskSpace);
        this.javaVersion.set(javaVersion);
        this.hostName.set(hostName);
        this.systemType.set(systemType);
        this.systemVersion.set(systemVersion);
        this.serverDate.set(serverDate);
    }

    public String getDiskSpace() {
        return diskSpace.get();
    }

    public SimpleStringProperty diskSpaceProperty() {
        return diskSpace;
    }

    public void setDiskSpace(String diskSpace) {
        this.diskSpace.set(diskSpace);
    }

    public String getServerDate() {
        return serverDate.get();
    }

    public SimpleStringProperty serverDateProperty() {
        return serverDate;
    }

    public void setServerDate(String serverDate) {
        this.serverDate.set(serverDate);
    }

    public String getServerName() {
        return serverName.get();
    }

    public SimpleStringProperty serverNameProperty() {
        return serverName;
    }

    public void setServerName(String serverName) {
        this.serverName.set(serverName);
    }

    public String getHostIP() {
        return hostIP.get();
    }

    public SimpleStringProperty hostIPProperty() {
        return hostIP;
    }

    public void setHostIP(String hostIP) {
        this.hostIP.set(hostIP);
    }

    public String getCPU() {
        return CPU.get();
    }

    public SimpleStringProperty CPUProperty() {
        return CPU;
    }

    public void setCPU(String CPU) {
        this.CPU.set(CPU);
    }

    public String getMEM() {
        return MEM.get();
    }

    public SimpleStringProperty MEMProperty() {
        return MEM;
    }

    public void setMEM(String MEM) {
        this.MEM.set(MEM);
    }

    public String getJavaVersion() {
        return javaVersion.get();
    }

    public SimpleStringProperty javaVersionProperty() {
        return javaVersion;
    }

    public void setJavaVersion(String javaVersion) {
        this.javaVersion.set(javaVersion);
    }

    public String getHostName() {
        return hostName.get();
    }

    public SimpleStringProperty hostNameProperty() {
        return hostName;
    }

    public void setHostName(String hostName) {
        this.hostName.set(hostName);
    }

    public String getSystemType() {
        return systemType.get();
    }

    public SimpleStringProperty systemTypeProperty() {
        return systemType;
    }

    public void setSystemType(String systemType) {
        this.systemType.set(systemType);
    }

    public String getSystemVersion() {
        return systemVersion.get();
    }

    public SimpleStringProperty systemVersionProperty() {
        return systemVersion;
    }

    public void setSystemVersion(String systemVersion) {
        this.systemVersion.set(systemVersion);
    }

    public String toString(){
        String str= ResultFormat(this.serverName.getValue())+"\t"+
                    ResultFormat(this.hostIP.getValue())+"\t"+
                    ResultFormat(this.CPU.getValue())+"\t"+
                    ResultFormat(this.MEM.getValue())+"\t"+
                    ResultFormat(this.diskSpace.getValue())+"\t"+
                    ResultFormat(this.javaVersion.getValue())+"\t"+
                    ResultFormat(this.hostName.getValue())+"\t"+
                    ResultFormat(this.systemType.getValue())+"\t"+
                    ResultFormat(this.systemVersion.getValue())+"\t"+
                    ResultFormat(this.serverDate.getValue());
        return str;
    }

    //去掉一个字符串中的换行符、回车符等，将连续多个空格替换成一个空格
    public static String ResultFormat(String string){
        Pattern p = Pattern.compile("\t|\r|\n");
        Matcher m = p.matcher(string);
        string = m.replaceAll("");
        string = string.replaceAll(" +", " ");
        return string;
    }

}
